package com.example.demo.customer;

import com.example.demo.exception.NotFoundException;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.logging.Logger;
import java.util.stream.Stream;

@Service
public class CustomerService {
 private  final static Logger LOGGER= (Logger) LoggerFactory.getLogger(CustomerService.class);
 private final CustomerRepo customerRepository;
 @Autowired
 public CustomerService(CustomerRepo customerRepo){
  this.customerRepository=customerRepo;
 }
 List<Customer> getCustomers() {
  LOGGER.info("getCustomers called");
  return customerRepository.findAll();
 }
  Customer getCustomer (Long id){
    return  customerRepository
      .findById(id)


           .orElseThrow(() ->{
            NotFoundException notFoundException =new NotFoundException("customer" + id+"无法找到");
            LOGGER.error("error: getCustomer {}"+ id, notFoundException);
            return notFoundException;
           });
  }

 }





